package alterlabviz;

import java.sql.*;
import java.util.ArrayList;
import processing.core.*;
import controlP5.*;


/* This class could be the top-level class from which all the others will be extended. 
 * Any high-level decisions will be implemented here and inherited to the others. For example, 
 * general decisions about the general look/feel can go here. 
 * 
 * Alternately, there may not really be any usefulness for such a thing, in which case this is 
 * a nice way to figure out how these custom controllers work. 
 * 
 * Thoughts - 
 * 1) Menu system for data interaction should be pretty straightforward with database/csvjdbc support.
 *    Issue may be how to send that info to a visualization. Could have menu in visualization to choose
 *    where things go (ie, start with this data on the ouside of a ring, then swap them) or do the drag/drop
 *    thing. I'm initially partial to a menu system because my intuition is the drag/drop might end up 
 *    a random walk. 
 *    
 *    One possibility could be that clicking on a part of the visualization changes the 'focus' of the
 *    data-selector. For instance, if you click one part of a visualization, you're filtering what data 
 *    is represented in that portion (ie, the ring). If you click another portion, the same menu modifies
 *    another part. 
 */
public class VizElement extends Controller{

	protected VizElement(ControlP5 theControlP5, String theName, 
			float theX, float theY, int theWidth, int theHeight) {
		super(theControlP5, (Tab)(theControlP5.getTab("default")), theName, theX, theY, theWidth, theHeight);
		// TODO Auto-generated constructor stub
	}
	
	
	/****** BEGIN DRAW METHODS ******/
	/* (TODO) - Separating these may be excessive?
	/* This is the actual draw method. Plan is not to overwrite this. */
	public void draw(PApplet theApplet) {
		predraw(theApplet);
		thedraw(theApplet);
		postdraw(theApplet);
	}
	
	/* The pre- and post- draw methods are for things 
	 * which shouldn't usually be altered between elements.*/
	public void predraw(PApplet theApplet) { 
	    theApplet.pushMatrix();
	    theApplet.translate(position().x(), position().y());
    	theApplet.fill(12,51,0); 
	    theApplet.rect(0,0,width,height);
	}
	/* Overwrite this. */
	public void thedraw(PApplet theApplet) {
		
		// notice how _not_ constraining the value allows you to pull the
		// rectangle outside the bounds of the current controller. could be
		// useful for drag/drop support. 
		if(isInside()) {
	    	theApplet.fill(255); 
			theApplet.rect(0,0,theApplet.mouseX-position.x(),theApplet.mouseY-position.y());
	        theApplet.println(theApplet.mouseX-position.x());
		}
		
	}
	public void postdraw(PApplet theApplet) {
	    theApplet.popMatrix();
	}
	/****** END DRAW METHODS ******/
	
	
	
	// overwrite the updateInternalEvents method to handle mouse and key inputs.
	public void updateInternalEvents(PApplet theApplet) {
		if(isInside()) {
			theApplet.println("mouse inside " + name() );
		}
	}
	
	
	@Override
	public void setValue(float arg0) {
		// TODO Auto-generated method stub
	}

	public void addToXMLElement(ControlP5XMLElement arg0) {
		// TODO Auto-generated method stub
	}

}
